package tmhm.shemes;


import java.awt.Point;
import java.util.ArrayList;

import tmhm.components.*;
import tmhm.gui.GuiLabel;
import tmhm.gui.GuiLine;
import tmhm.gui.GuiScheme;


public class Exec4 {

    private static NOT NOT1, NOT2, NOT3, NOT4, NOT5, NOT6, NOT7;
    private static XOR XOR1;
    private static OR OR1, OR2;
    private static MP MX7, MX8, MX9;
    private static IntToBools IBUS3bits;
    private static IntToInt IBUS3low4, IBUS3low3;
    private static GuiScheme gui;

    public static GuiScheme getGui() {
        return gui;
    }

    public static void init() {
        NOT1 = new NOT();
        NOT2 = new NOT();
        NOT3 = new NOT();
        NOT4 = new NOT();
        NOT5 = new NOT();
        NOT6 = new NOT();
        NOT7 = new NOT();
        XOR1 = new XOR();
        OR1 = new OR();
        OR2 = new OR();
        MX7 = new MP(8);
        MX8 = new MP(8);
        MX9 = new MP(2);
        IBUS3bits = new IntToBools(8, 8);
        IBUS3low4 = new IntToInt(16, 4);
        IBUS3low3 = new IntToInt(16, 3);


    }

    public static void connect() {

        NOT1.setInputPin(0, Exec2.PSWZ());
        XOR1.setInputPin(0, Exec2.PSWN());
        XOR1.setInputPin(1, Exec2.PSWV());
        NOT2.setInputPin(0, XOR1.getOut(0));
        OR1.setInputPin(0, XOR1.getOut(0));
        OR1.setInputPin(1, Exec2.PSWZ());
        NOT3.setInputPin(0, OR1.getOut(0));
        OR2.setInputPin(0, Exec2.PSWC());
        OR2.setInputPin(1, Exec2.PSWZ());
        NOT4.setInputPin(0, OR2.getOut(0));
        NOT5.setInputPin(0, Exec2.PSWC());
        NOT6.setInputPin(0, Exec2.PSWV());
        NOT7.setInputPin(0, Exec2.PSWN());

        MX7.setInputPin(0, Exec2.PSWZ());//eql
        MX7.setInputPin(1, NOT1.getOut(0));
        MX7.setInputPin(2, Exec2.PSWN());//neg
        MX7.setInputPin(3, NOT7.getOut(0));
        MX7.setInputPin(4, Exec2.PSWV());//ovf
        MX7.setInputPin(5, NOT6.getOut(0));
        MX7.setInputPin(6, Exec2.PSWC());//car
        MX7.setInputPin(7, NOT5.getOut(0));
        MX7.setCtrl(0, IBUS3bits.getOut(0));
        MX7.setCtrl(1, IBUS3bits.getOut(1));
        MX7.setCtrl(2, IBUS3bits.getOut(2));

        MX8.setInputPin(0, NOT3.getOut(0));
        MX8.setInputPin(1, NOT2.getOut(0));
        MX8.setInputPin(2, XOR1.getOut(0));
        MX8.setInputPin(3, OR1.getOut(0));
        MX8.setInputPin(4, NOT4.getOut(0));
        MX8.setInputPin(5, NOT5.getOut(0));
        MX8.setInputPin(6, Exec2.PSWC());
        MX8.setInputPin(7, OR2.getOut(0));
        MX8.setCtrl(0, IBUS3bits.getOut(0));
        MX8.setCtrl(1, IBUS3bits.getOut(1));
        MX8.setCtrl(2, IBUS3bits.getOut(2));

        MX9.setInputPin(0, MX7.getOut(0));
        MX9.setInputPin(1, MX8.getOut(0));
        MX9.setCtrl(0, IBUS3bits.getOut(3));

        IBUS3bits.setInputPin(0, Bus1.IBUS3());
        IBUS3low4.setInputPin(0, Bus1.IBUS3());
        IBUS3low3.setInputPin(0, Bus1.IBUS3());


    }

    public static void gui() {
        GuiLine line; // Pomocna promenljiva
        gui = new GuiScheme("tmhm/tmhm/images/Exec4.png");

        ArrayList<ArrayList<Point>> sections;
        ArrayList<Point> points;


        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(120, 41));
        points.add(new Point(237, 41));
        sections.add(points);
        points = new ArrayList<Point>();
        points.add(new Point(196, 41));
        points.add(new Point(196, 58));
        points.add(new Point(203, 58));
        sections.add(points);
        line = new GuiLine(sections, Exec2.PSWZ());
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(230, 58));
        points.add(new Point(237, 58));
        sections.add(points);
        line = new GuiLine(sections, NOT1.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(120, 81));
        points.add(new Point(130, 81));
        sections.add(points);
        line = new GuiLine(sections, Exec2.PSWN());
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(120, 92));
        points.add(new Point(130, 92));
        sections.add(points);
        line = new GuiLine(sections, Exec2.PSWV());
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(150, 86));
        points.add(new Point(237, 86));
        sections.add(points);
        line = new GuiLine(sections, XOR1.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(158, 86));
        points.add(new Point(158, 126));
        points.add(new Point(167, 126));
        sections.add(points);
        points = new ArrayList<Point>();
        points.add(new Point(196, 87));
        points.add(new Point(196, 103));
        points.add(new Point(203, 103));
        sections.add(points);
        line = new GuiLine(sections, XOR1.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(231, 103));
        points.add(new Point(237, 103));
        sections.add(points);
        line = new GuiLine(sections, NOT2.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(120, 137));
        points.add(new Point(168, 137));
        sections.add(points);
        line = new GuiLine(sections, Exec2.PSWZ());
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(188, 132));
        points.add(new Point(237, 132));
        sections.add(points);
        points = new ArrayList<Point>();
        points.add(new Point(196, 132));
        points.add(new Point(196, 149));
        points.add(new Point(203, 149));
        sections.add(points);
        line = new GuiLine(sections, OR1.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(231, 149));
        points.add(new Point(237, 149));
        sections.add(points);
        line = new GuiLine(sections, NOT3.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(120, 171));
        points.add(new Point(129, 171));
        sections.add(points);
        line = new GuiLine(sections, Exec2.PSWC());
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(120, 183));
        points.add(new Point(130, 183));
        sections.add(points);
        line = new GuiLine(sections, Exec2.PSWZ());
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(150, 177));
        points.add(new Point(237, 177));
        sections.add(points);
        line = new GuiLine(sections, OR2.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(196, 177));
        points.add(new Point(196, 194));
        points.add(new Point(203, 194));
        sections.add(points);
        line = new GuiLine(sections, OR2.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(231, 194));
        points.add(new Point(237, 194));
        sections.add(points);
        line = new GuiLine(sections, NOT4.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(374, 41));
        points.add(new Point(487, 41));
        sections.add(points);
        points = new ArrayList<Point>();
        points.add(new Point(445, 41));
        points.add(new Point(445, 58));
        points.add(new Point(453, 58));
        sections.add(points);
        line = new GuiLine(sections, Exec2.PSWC());
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(480, 58));
        points.add(new Point(487, 58));
        sections.add(points);
        line = new GuiLine(sections, NOT5.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(374, 86));
        points.add(new Point(487, 86));
        sections.add(points);
        points = new ArrayList<Point>();
        points.add(new Point(445, 86));
        points.add(new Point(445, 103));
        points.add(new Point(453, 103));
        sections.add(points);
        line = new GuiLine(sections, Exec2.PSWV());
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(480, 103));
        points.add(new Point(487, 103));
        sections.add(points);
        line = new GuiLine(sections, NOT6.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(374, 132));
        points.add(new Point(487, 132));
        sections.add(points);
        points = new ArrayList<Point>();
        points.add(new Point(445, 133));
        points.add(new Point(445, 149));
        points.add(new Point(453, 149));
        sections.add(points);
        line = new GuiLine(sections, Exec2.PSWN());
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(480, 149));
        points.add(new Point(487, 149));
        sections.add(points);
        line = new GuiLine(sections, NOT7.getOut(0));
        gui.addLine(line);



sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(144,380));
points.add(new Point(144,526));
sections.add(points);
line=new GuiLine(sections,Bus1.IBUS1());
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(125,395));
points.add(new Point(125,511));
sections.add(points);
line=new GuiLine(sections,Bus1.IBUS2());
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(106,410));
points.add(new Point(106,496));
sections.add(points);
line=new GuiLine(sections,Bus1.IBUS3());
gui.addLine(line);



sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(106,463));
points.add(new Point(422,463));
sections.add(points);
line=new GuiLine(sections,IBUS3low4.getOut(0));
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(272,463));
points.add(new Point(272,428));
sections.add(points);
line=new GuiLine(sections,IBUS3low3.getOut(0));
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(256,424));
points.add(new Point(256,417));
sections.add(points);
line=new GuiLine(sections,IBUS3bits.getOut(2));
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(272,427));
points.add(new Point(272,417));
sections.add(points);
line=new GuiLine(sections,IBUS3bits.getOut(1));
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(287,424));
points.add(new Point(287,417));
sections.add(points);
line=new GuiLine(sections,IBUS3bits.getOut(0));
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(407,424));
points.add(new Point(407,417));
sections.add(points);
line=new GuiLine(sections,IBUS3bits.getOut(2));
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(422,427));
points.add(new Point(422,417));
sections.add(points);
line=new GuiLine(sections,IBUS3bits.getOut(1));
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(437,424));
points.add(new Point(437,417));
sections.add(points);
line=new GuiLine(sections,IBUS3bits.getOut(0));
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(422,463));
points.add(new Point(511,463));
points.add(new Point(511,351));
sections.add(points);
line=new GuiLine(sections,IBUS3bits.getOut(3));
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(422,463));
points.add(new Point(422,428));
sections.add(points);
line=new GuiLine(sections,IBUS3low3.getOut(0));
gui.addLine(line);


sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(236,398));
points.add(new Point(243,398));
sections.add(points);
line=new GuiLine(sections,Exec2.PSWZ());
gui.addLine(line);

sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(236,380));
points.add(new Point(243,380));
sections.add(points);
line=new GuiLine(sections,NOT1.getOut(0));
gui.addLine(line);

sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(236,361));
points.add(new Point(243,361));
sections.add(points);
line=new GuiLine(sections,Exec2.PSWN());
gui.addLine(line);

sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(236,342));
points.add(new Point(243,342));
sections.add(points);
line=new GuiLine(sections,NOT7.getOut(0));
gui.addLine(line);

sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(236,323));
points.add(new Point(243,323));
sections.add(points);
line=new GuiLine(sections,Exec2.PSWV());
gui.addLine(line);

sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(236,304));
points.add(new Point(243,304));
sections.add(points);
line=new GuiLine(sections,NOT6.getOut(0));
gui.addLine(line);

sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(236,285));
points.add(new Point(243,285));
sections.add(points);
line=new GuiLine(sections,Exec2.PSWC());
gui.addLine(line);

sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(236,267));
points.add(new Point(243,267));
sections.add(points);
line=new GuiLine(sections,NOT5.getOut(0));
gui.addLine(line);

sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(387,398));
points.add(new Point(394,398));
sections.add(points);
line=new GuiLine(sections,NOT3.getOut(0));
gui.addLine(line);

sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(387,380));
points.add(new Point(394,380));
sections.add(points);
line=new GuiLine(sections,NOT2.getOut(0));
gui.addLine(line);

sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(387,361));
points.add(new Point(394,361));
sections.add(points);
line=new GuiLine(sections,XOR1.getOut(0));
gui.addLine(line);

sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(387,342));
points.add(new Point(394,342));
sections.add(points);
line=new GuiLine(sections,OR1.getOut(0));
gui.addLine(line);


sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(386,323));
points.add(new Point(394,323));
sections.add(points);
line=new GuiLine(sections,NOT4.getOut(0));
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(387,304));
points.add(new Point(394,304));
sections.add(points);
line=new GuiLine(sections,NOT5.getOut(0));
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(387,285));
points.add(new Point(394,285));
sections.add(points);
line=new GuiLine(sections,Exec2.PSWC());
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(387,267));
points.add(new Point(394,267));
sections.add(points);
line=new GuiLine(sections,OR2.getOut(0));
gui.addLine(line);


sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(300,332));
points.add(new Point(319,332));
points.add(new Point(319,238));
points.add(new Point(469,238));
points.add(new Point(469,314));
points.add(new Point(488,314));
sections.add(points);
line=new GuiLine(sections,MX7.getOut(0));
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(450,332));
points.add(new Point(488,332));
sections.add(points);
line=new GuiLine(sections,MX8.getOut(0));
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(533,323));
points.add(new Point(541,323));
sections.add(points);
line=new GuiLine(sections,MX9.getOut(0));
gui.addLine(line);


         // LABELE:
        gui.addLabel(new GuiLabel(148, 402, Bus1.IBUS1()));
        gui.addLabel(new GuiLabel(129, 432, Bus1.IBUS2()));
        gui.addLabel(new GuiLabel(76, 462, Bus1.IBUS3()));
        gui.addLabel(new GuiLabel(210, 477, IBUS3low4.getOut(0)));
        gui.addLabel(new GuiLabel(277, 453, IBUS3low3.getOut(0)));
        gui.addLabel(new GuiLabel(426, 453, IBUS3low3.getOut(0)));
        
    }

    public static Pin brpom() {
        return MX9.getOut(0);
    }
}
